<template>
    <view>
        <!--标题和返回-->
		<cu-custom :bgColor="NavBarColor" isBack :backRouterName="backRouteName">
			<block slot="backText">返回</block>
			<block slot="content">补贴券</block>
		</cu-custom>
		 <!--表单区域-->
		<view>
			<form>
              <view class="cu-form-group">
                <view class="flex align-center">
                  <view class="title"><text space="ensp">逻辑删除：</text></view>
                  <input type="number" placeholder="请输入逻辑删除" v-model="model.delFlag"/>
                </view>
              </view>
              <view class="cu-form-group">
                <view class="flex align-center">
                  <view class="title"><text space="ensp">时间戳：</text></view>
                  <input  placeholder="请输入时间戳" v-model="model.ts"/>
                </view>
              </view>
              <view class="cu-form-group">
                <view class="flex align-center">
                  <view class="title"><text space="ensp">租户id：</text></view>
                  <input type="number" placeholder="请输入租户id" v-model="model.tenantId"/>
                </view>
              </view>
              <view class="cu-form-group">
                <view class="flex align-center">
                  <view class="title"><text space="ensp">补贴券名称：</text></view>
                  <input  placeholder="请输入补贴券名称" v-model="model.name"/>
                </view>
              </view>
              <view class="cu-form-group">
                <view class="flex align-center">
                  <view class="title"><text space="ensp">补贴券用于：</text></view>
                  <input  placeholder="请输入补贴券用于" v-model="model.used"/>
                </view>
              </view>
              <view class="cu-form-group">
                <view class="flex align-center">
                  <view class="title"><text space="ensp">补贴券类型：</text></view>
                  <input  placeholder="请输入补贴券类型" v-model="model.type"/>
                </view>
              </view>
              <my-date label="生效日期：" v-model="model.effectDate" placeholder="请输入生效日期"></my-date>
              <my-date label="过期日期：" v-model="model.expireDate" placeholder="请输入过期日期"></my-date>
              <my-date label="发放开始时间：" v-model="model.startTime" placeholder="请输入发放开始时间"></my-date>
              <my-date label="发放截止时间：" v-model="model.endTime" placeholder="请输入发放截止时间"></my-date>
              <view class="cu-form-group">
                <view class="flex align-center">
                  <view class="title"><text space="ensp">补贴金额：</text></view>
                  <input type="number" placeholder="请输入补贴金额" v-model="model.price"/>
                </view>
              </view>
              <view class="cu-form-group">
                <view class="flex align-center">
                  <view class="title"><text space="ensp">发放数量：</text></view>
                  <input type="number" placeholder="请输入发放数量" v-model="model.num"/>
                </view>
              </view>
              <view class="cu-form-group">
                <view class="flex align-center">
                  <view class="title"><text space="ensp">已发放数量：</text></view>
                  <input type="number" placeholder="请输入已发放数量" v-model="model.usedNum"/>
                </view>
              </view>
              <view class="cu-form-group">
                <view class="flex align-center">
                  <view class="title"><text space="ensp">有效期类型：</text></view>
                  <input type="number" placeholder="请输入有效期类型" v-model="model.validateType"/>
                </view>
              </view>
              <view class="cu-form-group">
                <view class="flex align-center">
                  <view class="title"><text space="ensp">有效天数：</text></view>
                  <input type="number" placeholder="请输入有效天数" v-model="model.validateDays"/>
                </view>
              </view>
              <view class="cu-form-group">
                <view class="flex align-center">
                  <view class="title"><text space="ensp">是否过期：</text></view>
                  <input type="number" placeholder="请输入是否过期" v-model="model.expireFlag"/>
                </view>
              </view>
              <view class="cu-form-group">
                <view class="flex align-center">
                  <view class="title"><text space="ensp">满减金额：</text></view>
                  <input type="number" placeholder="请输入满减金额" v-model="model.withAmount"/>
                </view>
              </view>
              <view class="cu-form-group">
                <view class="flex align-center">
                  <view class="title"><text space="ensp">是否置顶：</text></view>
                  <input type="number" placeholder="请输入是否置顶" v-model="model.topFlag"/>
                </view>
              </view>
              <view class="cu-form-group">
                <view class="flex align-center">
                  <view class="title"><text space="ensp">剩余数量：</text></view>
                  <input type="number" placeholder="请输入剩余数量" v-model="model.leftNum"/>
                </view>
              </view>
				<view class="padding">
					<button class="cu-btn block bg-blue margin-tb-sm lg" @click="onSubmit">
						<text v-if="loading" class="cuIcon-loading2 cuIconfont-spin"></text>提交
					</button>
				</view>
			</form>
		</view>
    </view>
</template>

<script>
    import myDate from '@/components/my-componets/my-date.vue'

    export default {
        name: "TbAllowanceForm",
        components:{ myDate },
        props:{
          formData:{
              type:Object,
              default:()=>{},
              required:false
          }
        },
        data(){
            return {
				CustomBar: this.CustomBar,
				NavBarColor: this.NavBarColor,
				loading:false,
                model: {},
                backRouteName:'index',
                url: {
                  queryById: "/recycle/tbAllowance/queryById",
                  add: "/recycle/tbAllowance/add",
                  edit: "/recycle/tbAllowance/edit",
                },
            }
        },
        created(){
             this.initFormData();
        },
        methods:{
           initFormData(){
               if(this.formData){
                    let dataId = this.formData.dataId;
                    this.$http.get(this.url.queryById,{params:{id:dataId}}).then((res)=>{
                        if(res.data.success){
                            console.log("表单数据",res);
                            this.model = res.data.result;
                        }
                    })
                }
            },
            onSubmit() {
                let myForm = {...this.model};
                this.loading = true;
                let url = myForm.id?this.url.edit:this.url.add;
				this.$http.post(url,myForm).then(res=>{
				   console.log("res",res)
				   this.loading = false
				   this.$Router.push({name:this.backRouteName})
				}).catch(()=>{
					this.loading = false
				});
            }
        }
    }
</script>
